#include <iostream>
#include <string>
#include <cstring>
#include <error.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>

int main()
{
    int listen_fd = socket(AF_INET,SOCK_STREAM, 0);

    struct sockaddr_in local;
    bzero(&local, sizeof(local));
    local.sin_family = AF_INET;
    local.sin_port = htons(8080);
    local.sin_addr.s_addr = INADDR_ANY;
    int ret = bind(listen_fd, (sockaddr*)&local, sizeof(local));
    if(ret == -1)
    {
        std::cout << "error: " << strerror(errno) << std::endl;
        exit(1);
    }
    std::cout << "first bind success!" << std::endl;

    bzero(&local, sizeof(local));
    local.sin_port = htons(8081);
    local.sin_family = AF_INET;
    local.sin_addr.s_addr = INADDR_ANY;
    ret = bind(listen_fd, (sockaddr*)&local, sizeof(local));    
    if(ret == -1)
    {
        std::cout << "error: " << strerror(errno) << std::endl;
        exit(1);
    }
    
    listen(listen_fd, 5);
    struct sockaddr_in peer;
    socklen_t len = sizeof(peer);
    int fd = accept(listen_fd, (sockaddr*)&peer, &len);
    if(fd == -1)
    {
        std::cout << "error: " << strerror(errno) << std::endl;
        exit(1);
    }

    return 0;
}
